import 'package:safetymonitor/app/core/ext/time.dart';

enum TimeInterval {
  day,
  week,
  month,
  year,
  ;

  String get title {
    switch (this) {
      case day:
        return '今日';
      case week:
        return '本周';
      case month:
        return '本月';
      case year:
        return '本年';
    }
  }

  /// 时间间隔从开始到结束String
  (String, String) get startToEnd {
    final now = DateTime.now();
    switch (this) {
      case day:
        return (now.subtract(const Duration(days: 1)).toStr, now.toStr);
      case week:
        final weekDay = now.weekday;
        final start = now.subtract(Duration(days: weekDay - 1));
        final end = now.add(Duration(days: 7 - weekDay));
        return (start.toStr, end.toStr);
      case month:
        final start = DateTime(now.year, now.month, 1);
        final end = DateTime(now.year, now.month + 1, 0);
        return (start.toStr, end.toStr);
      case year:
        final start = DateTime(now.year, 1, 1);
        final end = DateTime(now.year, 12, 31);
        return (start.toStr, end.toStr);
    }
  }
}